<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="app">
    =={{msg}}==={{count}}===obj:{{obj}}
    <hr />
    <button @click="handle">+10</button>
  </div>
  <script src="https://cdn.bootcdn.net/ajax/libs/vue/2.7.14/vue.min.js"></script>
  <script>
    var vm = new Vue({
      el: "#app",
      data: {
        msg: 'hello  vue',
        count: 10,
        obj: {
          num: 1
        }
      },
      methods: {
        handle () {
          this.obj.num += 2
        }
      },
      watch: {
        // 监听现有数据
        "count" (newVal, oldVal) {
          console.log(newVal, oldVal, 1111);
        },
        //监听复杂数据
        /* 方法1： */
        // 'obj.num' () {
        //   console.log(2222);
        // }
        /* 方法2 */
        obj: {
          //hander监控处理函数
          handler (newVal) {
            console.log(newVal.num, 2222);
          },
          deep: true, //深度监听
          immediate: true //开启立即监听
        }
      }
    })

        // console.log(vm, 2222);
  </script>
</body>

</html>